/*
 * my_assert.c
 *
 *  Created on: Jul 3, 2024
 *      Author: root
 */
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include "basic_header.h"

static char buffer[COMMON_BUFFER_SIZE];
void my_assert(const void *expr, const void *file, int line, const void *fun,
		const char *str) {
	FILE *fd = fopen(ASSERT_FILE, "w");

	struct timeval tv;
	gettimeofday(&tv, NULL);
	struct tm *tm = localtime(&tv.tv_sec);

	if (fd != NULL) {
		snprintf(buffer, sizeof(buffer),
				"%02d-%02d-%02d %02d-%02d-%02d %s:%d:%s %s %s\r\n",
				1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour,
				tm->tm_min, tm->tm_sec, (char*) file, line, (char*) fun,
				(char*) expr, str);
		fwrite(buffer, 1, strlen(buffer), fd);
	}

	if (fd != NULL) {
		fclose(fd);
	}
}
